<include file="Public/header" />
<style>
.shop_sort .shop_sort_title{width:10%;}
.shop_sort .shop_sort_set i{font-size: 18px;line-height: 34px;margin-left: 10px;cursor: pointer;color:#888}
.shop_sort .shop_sort_set .service{float:left;line-height:34px;text-align:center;width:60px;}
.pic_container{float:left;width:88%;}
.pic_wrapper{float:left;width:110px;height:110px;position:relative;}
.pic_wrapper img{margin:10px 10px 10px 0;max-width:100px;max-height:100px;z-index:1;}
.pic_wrapper div{display:none;position:absolute;top:10px;width: 100px;height: 100px;color: #fff;background: rgba(0,0,0,0.6);line-height:100px;vertical-align: middle;text-align: center;font-size:18px;cursor:pointer;}
</style>
        <div class="comm-top">
        	<include file="Goods/nav" act_nav="add_goods"/>
            <h4 style="margin-bottom:0">{:$formData['id']?'修改':'添加'}整车信息</h4>
            <div class="add_page_top"></div>
        </div>
        <form id="dataFrom" onsubmit="return false;">
            <input type="hidden" name="info[type]" value="1" />
            <input type="hidden" name="info[id]" value="{$formData.id}" />
            <div class="shop_sort_box">
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4><must>*</must>商品名称：</h4></div>
                    <div class="shop_sort_set">
                        <input class="shop_sort_text" name="info[goods_name]" value="{$formData.goods_name}" type="text" placeholder="请输入商品名称"/>
                    </div>
                </div>

                <div class="shop_sort">
                    <div class="shop_sort_title"><h4><must>*</must>商品配图：</h4></div>
                    <div class="shop_sort_set" style="position:relative;">
                        <input class="shop_sort_text" type="text" onclick="up_img_fun('{:U('Upload/index')}')" />
                        <a href="javascript:void(0);" class="btn-upload" onclick="up_img_fun('{:U('Upload/index')}')">
                            <i class="icons icons-upload"></i>上传
                        </a>
                        <span class="input_span_extra">&nbsp;&nbsp;&nbsp;建议图片尺寸260px*260px</span>
                    </div>
                    <div class="pic_container">
                    <foreach name="formData.goods_pics" item="val">
                    	<div class="pic_wrapper">
                    		<input type="hidden" name="goods_pics[]" value="{$val}"/>
                            <img src="{$val}"/>
                            <div>删 除</div>
                        </div>
                    </foreach>
                    </div>
                </div>

                <div class="shop_sort">
                    <div class="shop_sort_title"><h4><must>*</must>商品价格：</h4></div>
                    <div class="shop_sort_set">
                        <input class="shop_sort_text" id="price" name="info[price]" value="{$formData.price}" type="number" placeholder="请输入价格（单位：成长值）"/>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title" style="float:left;"><h4><must>*</must>规格（颜色）：</h4></div>
                    <div style="float:left;width:88%;">
                    	<if condition="$formData['spec'] neq null">
                    		<foreach name="formData.spec" item="val" key="n">
                    		<div class="shop_sort_set">
		                        <input class="shop_sort_text" name="spec[{$n}][color]" style="width:250px;" value="{$val.color}" type="text" placeholder="颜色"/>
		                        <input class="shop_sort_text" name="spec[{$n}][store]" style="margin-left:10px;width:140px;" value="{$val.store}" type="number" placeholder="库存"/>
		                        <input type="hidden" name="spec[{$n}][id]" value="{$val.id}"/>
		                    	<i class="glyphicon glyphicon-trash"  onclick="dele_spec(this)"></i>
		                    </div>
                    		</foreach>
                    	<else/>
	                    	<div class="shop_sort_set">
		                        <input class="shop_sort_text" name="spec[0][color]" style="width:250px;" type="text" placeholder="颜色"/>
		                        <input class="shop_sort_text" name="spec[0][store]" style="margin-left:10px;width:140px;" type="number" placeholder="库存"/>
		                    	<i class="glyphicon glyphicon-trash"  onclick="dele_spec(this)"></i>
		                    </div>
	                    </if>
	                    <div class="shop_sort_set" style="margin-top:10px;" id="addSpec">
                        	<span onclick="add_spec()" class="btngreen30">添加规格</span>
	                    </div>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>可选服务：</h4></div>
                    <div style="float:left;width:88%;">
	                    <div class="shop_sort_set">
	                        <span class="service">VIP通道</span>
	                        <input class="shop_sort_text" style="width:280px;" name="info[vip_price]" value="{$formData.vip_price}" type="number" placeholder=""/>
	                        <span class="service">元/件</span>
	                    </div>
<!-- 	                    <div class="shop_sort_set rdo"> -->
<!-- 	                        <label class="lbl"><span><input type="radio" name="info[vip_status]" {:$formData['vip_status']!='2'?'checked':''} value='1'></span><span>可用</span></label> -->
<!-- 	                        <label class="lbl"><span><input type="radio" name="info[vip_status]" {:$formData['vip_status']=='2'?'checked':''} value='2'></span><span>不可用</span></label> -->
<!-- 	                    </div> -->
	                    <div class="shop_sort_set">
	                        <span class="service">按天付首付</span>
	                        <input class="shop_sort_text" style="width:280px;" id="per_first_price" name="info[per_first_price]" value="{$formData.per_first_price}" type="number" placeholder=""/>
	                        <span class="service">元/件</span>
	                    </div>
	                    <div class="shop_sort_set">
	                        <span class="service">分期还款</span>
	                        <input class="shop_sort_text" style="width:280px;" id="per_price" name="info[per_price]" value="{$formData.per_price}" type="number" placeholder=""/>
	                        <span class="service">元/天</span>
	                    </div>
						<div class="shop_sort_set">
	                        <span class="service">还款天数</span>
	                        <input class="shop_sort_text" style="width:280px;" id="per_days" name="info[per_days]" value="{$formData.per_days}" type="text" placeholder="还款天数" readonly/>
	                        <span class="service">天</span>
	                    </div>
						
<!-- 	                    <div class="shop_sort_set rdo"> -->
<!-- 	                        <label class="lbl"><span><input type="radio" name="info[per_status]" {:$formData['per_status']!='2'?'checked':''} value='1'></span><span>可用</span></label> -->
<!-- 	                        <label class="lbl"><span><input type="radio" name="info[per_status]" {:$formData['per_status']=='2'?'checked':''} value='2'></span><span>不可用</span></label> -->
<!-- 	                    </div> -->

					</div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>总销量：</h4></div>
                    <div class="shop_sort_set">
                        <input class="shop_sort_text" name="info[sale_count]" value="{$formData.sale_count|default=0}" type="text" placeholder="请输入商品总销量"/>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4><must>*</must>商品简介：</h4></div>
                    <div class="shop_sort_set">
                        <textarea class="shop_sort_text" name="info[profile]" placeholder="请输入介绍" style="height:80px;">{$formData.profile}</textarea>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4><must>*</must>商品详情：</h4></div>
                    <div class="shop_sort_set">
                        <textarea  id="detail" name="info[detail]" style="height:120px;width:600px;">{$formData.detail}</textarea>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>状态：</h4></div>
                    <div class="shop_sort_set rdo">
                        <label class="lbl"><span><input type="radio" name="info[status]" {:$formData['status']!='2'?'checked':''} value='1'></span><span>上架</span></label>
                        <label class="lbl"><span><input type="radio" name="info[status]" {:$formData['status']=='2'?'checked':''} value='2'></span><span>下架</span></label>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title">
                        <h4>&nbsp;</h4>
                    </div>
                    <div class="shop_sort_set">
                        <span onclick="save(this);return false" id="saveBtn" class="btngreen30">完成</span>
                        &nbsp;&nbsp;&nbsp;
                        <span onclick="history.go(-1);" class="btngray30">返回</span>
                    </div>
                </div>
            </div>
        </form>
        
<!-- 上传图片开始 -->	
<link rel="stylesheet" type="text/css" href="__PUBLIC__/upimg/css/upimg.css" />
<script type="text/javascript" src="__PUBLIC__/upimg/upimg.js"></script>
<script type="text/javascript">
/**
 * up_img_fun(up_img_php) 执行上传的函数，微沟通图片上传的改版
 * @param string up_img_php 后台处理图片上传的文件
 * 
 * up_img_notify(img_path) 上传回调函数
 * @param string img_path 返回的图片地址，图片仍放在/data/image_c/下
 */
function up_img_notify(img_path){
    var str = '';
    str += '<div class="pic_wrapper">';
    str += '<input type="hidden" name="goods_pics[]" value="'+img_path+'"/>';
    str += '<img src="'+img_path+'"/>';
    str += '<div>删 除</div>';
	str += '</div>';
	$('.pic_container').append(str);
}
</script>
<!-- 上传图片结束 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
<script>
$(function(){
    //初始化编辑器
    UE.getEditor('detail', {
        toolbars: [['source','bold','italic','underline','fontsize','forecolor','backcolor','pasteplain',
        'insertorderedlist','cleardoc','link','simpleupload','emotion','map','inserttable',
        //'insertimage',//多图上传
        ]]
    });
    $('.pic_container').on('mouseover','.pic_wrapper img',function(){
    	$(this).next().show();
    })
    $('.pic_container').on('mouseout','.pic_wrapper div',function(){
    	$(this).hide();
    })
    $('.pic_container').on('click','.pic_wrapper div',function(){
    	$(this).parent('.pic_wrapper').remove();
    })
	$('#price,#per_first_price,#per_price').bind('keyup',function(){
		var price = parseFloat($.trim($('#price').val()));
		var per_first_price = parseFloat($.trim($('#per_first_price').val()));
		var per_price = parseFloat($.trim($('#per_price').val()));
		var diff_price = price-per_first_price;
		if(diff_price<=0) $('#per_days').val(0);
		if(per_price == 0)$('#per_days').val('');
		if((diff_price/per_price).toFixed(2) == (diff_price/per_price)){
			$('#per_days').css('color','#555').val(Math.floor(diff_price/per_price));
		}else{
			$('#per_days').css('color','red').val((diff_price/per_price).toFixed(2));
		}
	});
});
var spec_index = 1000;
function add_spec(){
	spec_index++;
	var str = '';
	str += '<div class="shop_sort_set">';
	str += '<input class="shop_sort_text" name="spec['+spec_index+'][color]" style="width:250px;" type="text" placeholder="颜色"/>';
	str += '<input class="shop_sort_text" name="spec['+spec_index+'][store]" style="margin-left:10px;width:140px;" type="number" placeholder="库存"/>';
	str += '<i class="glyphicon glyphicon-trash" onclick="dele_spec(this)"></i>';
	str += '</div>';
	$('#addSpec').before(str);
}
function dele_spec(obj){
	if($('#addSpec').siblings().length <= 1)return false;
	$(obj).parent('.shop_sort_set').remove();
}
function save(obj){
    $.post('{:U("add_goods")}',$('#dataFrom').serialize(),function(res){
        if(res.status == 1){
            note_info(res.info,obj);
            setTimeout('window.location.href="'+document.referrer+'"',1200);
        }else{
            note_info(res.info,obj,'warn');
        }
    })
}
</script>
<include file="Public/footer"/>
